package com.pkk.spring.cloud.service.gateway.selector;

import com.pkk.spring.cloud.service.gateway.annotation.RouteDefinitionRepositoryAdviceModel;
import com.pkk.spring.cloud.service.gateway.route.InMysqlRouteDefinitionRepository;
import com.pkk.spring.cloud.service.gateway.route.InRedisRouteDefinitionRepository;
import lombok.extern.slf4j.Slf4j;

/**
 * 路由定义信息持久层的选择选择器
 *
 * @author peikunkun
 * @version V1.0
 * @date 2021-01-15 17:40
 **/
@Slf4j
public class RouteDefinitionRepositoryImportSelector extends RouteDefinitionRepositoryAdviceModelImportSelector {


  /**
   * 获取路由定义持久方式的配置bean
   *
   * @param model
   * @return java.lang.String[]
   * @Param model
   * @author peikunkun
   * @date 2021/1/15 0015 下午 5:50
   * @since
   */
  @Override
  protected String[] selectImports(RouteDefinitionRepositoryAdviceModel model) {
    if (!isEnabled()) {
      log.warn("没有启用动态路由配置，如需启用请求改配置[penguin.cloud.dynamic.route.enabled:true]");
      return NO_IMPORTS;
    }

    switch (model) {
      case REDIS:
        return new String[]{InRedisRouteDefinitionRepository.class.getName()};
      case MYSQL:
        return new String[]{InMysqlRouteDefinitionRepository.class.getName()};
      case NONE:
        return NO_IMPORTS;
      default:
        return null;
    }
  }


}
